home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1991 …esperately Seeking Seven / Desperately Seeking Seven.2mg / Dev.CD.8 / Essentials / Tools / File.Type.Notes / FTN.E0.8000 < prev    next >
Encoding:
Text File  |  1989-07-23  |  26.5 KB  |  510 lines  |  [04] ASCII Text (0x0000)

  1. Apple II
  2. File Type Notes
  3. _____________________________________________________________________________
  4.                                                   Developer Technical Support
  5.  
  6.  
  7. File Type:         $E0 (224)
  8. Auxiliary Type:    $8000
  9.  
  10. Full Name:     Binary II File
  11. Short Name:    Binary II File
  12.  
  13. Written by:    Matt Deatherage                                      July 1989
  14.  
  15. Files of this type and auxiliary type contain other files with their 
  16. attributes encoded in Binary II format.
  17. _____________________________________________________________________________
  18.  
  19. Binary II is a widely used and accepted standard for keeping file attributes 
  20. with files as they are transferred, usually by modem or other form of 
  21. telecommunication.  Files that are known Binary II files should be written to 
  22. disk with file type $E0 and auxiliary type $8000 as a clear indication to 
  23. other programs that the file contains files with Binary II specifications.
  24.  
  25. Binary II was developed by Gary B. Little, author of the Point-To-Point 
  26. communication's product and author of several Apple II reference books.  He is 
  27. also Apple's Product Manager for third-party Development Tools and Languages.  
  28. Gary welcomes your comments and suggestions on the Binary II standard at the 
  29. following address:
  30.  
  31.                 Gary B. Little
  32.                 3304 Plateau Drive
  33.                 Belmont, CA  94002
  34.  
  35.                 AppleLink:                      LITTLE
  36.                 AppleLink--Personal Edition:    GaryLittle
  37.                 CompuServe:                     70135,1007
  38.                 GEnie:                          GARY.LITTLE
  39.  
  40.  
  41. Why Binary II?
  42.  
  43. Transferring Apple II files in binary form to commercial information services 
  44. and bulletin boards (referred to in this Note as "hosts") can be, to put it 
  45. mildly, a frustrating exercise.  Although most hosts are able to receive a 
  46. file's data in binary form (using protocols such as XMODEM), they don't 
  47. receive the file's all-important attribute bytes.  All the common Apple II 
  48. file system, notably the ProDOS file system, store the attributes inside the 
  49. disk directory, not inside the file itself.
  50.  
  51. The ProDOS attributes are the access code, file type code, auxiliary type 
  52. code, storage type code, date of creation and last modification, time of 
  53. creation and last modification, the file size, and the name of the file 
  54. itself.  Under GS/OS, the same parameters exist for other file systems as well 
  55. as file system-specific information and two-forked file information.  It is 
  56. usually not possible to use a ProDOS file's data without knowing the file's 
  57. attributes (particularly the file type, auxiliary type, and size).  Therefore, 
  58. ProDOS files uploaded in binary format to a host are useless to those who 
  59. download them.  The same is true for DOS 3.3 and Pascal files.
  60.  
  61. Many Apple II communication programs use special protocols for transferring 
  62. file attributes during a binary file transfer, but none of these protocols 
  63. have been implemented by hosts.  These programs are only useful for exchanging 
  64. files with another Apple II running the same program.
  65.  
  66. Without a standard like Binary II, the only acceptable way to transfer an 
  67. Apple II file to a host is to convert it into ASCII text before sending it.  
  68. Such a text file would contain a listing of an AppleSoft program, or a series 
  69. of Apple II monitor commands (e.g., 300:A4 32).  Someone downloading a file 
  70. can convert it to binary form using the AppleSoft EXEC command.
  71.  
  72. The main disadvantage of this technique is that the text version of the file 
  73. is over three times the size of the original binary file, making it expensive 
  74. (in terms of time and money) to upload and download.  It is also awkward, and 
  75. sometimes impossible, to perform the binary-to-text or text-to-binary 
  76. conversion.
  77.  
  78. The solution to the problem is to upload an encoded binary file which contains 
  79. not just the file's data, but the file's attributes as well.  Someone 
  80. downloading such a file can then use a conversion program to strip the 
  81. attributes from the file and create a file with the required attributes.
  82.  
  83. This Note describes such a format:  Binary II.  The description of the format 
  84. is detailed for the purpose of allowing software developers to implement it in 
  85. Apple II communication programs.
  86.  
  87.  
  88. What Binary II is Not
  89.  
  90. Binary II is not an archival or compression standard.  It is designed to be a 
  91. simple method to keep the attributes normally in a disk file's directory entry 
  92. with the file as it is transferred.  Although multiple files may be placed 
  93. together with Binary II, this is a matter of convenience for telecommunication 
  94. programs.
  95.  
  96. A true archival standard must be designed as such, with the capability to 
  97. manipulate files within the archive as well as linking them together 
  98. (compressed or uncompressed) for transfer.  NuFX (documented in Apple II File 
  99. Type Note for File Type $E0, Auxiliary Type $8002) is a good example of a 
  100. robust, full-featured Apple II archival standard.
  101.  
  102. Binary II is primarily designed to be added to and subtracted from files "on-
  103. the-fly" by telecommunication programs.  Binary II files should only be found 
  104. on disks when they are transferred by a telecommunication program that does 
  105. not have Binary II capabilities, in which case a separate utility (such as 
  106. Binary Library Utility by Floyd Zink, Jr.) must be used to extract the files.  
  107. Telecommunication programs should be able to transfer files without Binary II 
  108. processing, however, they should support Binary II processing as a default.
  109.  
  110.  
  111. The Binary II File Format
  112.  
  113. The Binary II form of a standard file consists of a 128-byte file information 
  114. header followed by the file's data.  The data portion of the file is padded 
  115. with nulls ($00 bytes), if necessary, to ensure the data length is an even 
  116. multiple of 128 bytes.
  117.  
  118. The file information header contains four ID bytes, the attributes of the file 
  119. (in ProDOS 8 form), and some control information.
  120.  
  121. The structure of the header is as follows:
  122.  
  123. +000    ID Bytes   3 Bytes  These three bytes are always $0A $47 $4C 
  124.                             for identification purposes, so programs 
  125.                             may recognize Binary II files as they are 
  126.                             received.
  127. +003    Access Code Byte    ProDOS 8 access byte.
  128. +004    File Type  Byte     ProDOS 8 file type.
  129. +005    Aux Type   Word     ProDOS 8 auxiliary type.
  130. +007    Storage Type Byte   ProDOS 8 storage type value.
  131. +008    File Size   Word    The size of the file in 512-byte blocks.
  132. +010    Mod. Date   2 Bytes Date of modification, in ProDOS 8 
  133.                             compressed format.
  134. +012    Mod. Time   2 Bytes Time of modification, in ProDOS 8 
  135.                             compressed format.
  136. +014    Create Date 2 Bytes Date of creation, in ProDOS 8 
  137.                             compressed format.
  138. +016    Create Time 2 Bytes Time of creation, in ProDOS 8 
  139.                             compressed format.
  140. +018    ID Byte     Byte    A fourth ID byte.  This must always be 
  141.                             $02.
  142. +019    Reserved    Byte    Reserved, must be set to zero.
  143. +020    EOF         3 Bytes The end-of-file value for the file (low 
  144.                             byte first).
  145. +023    File Name   String  Pascal string containing the ASCII 
  146.                             filename or partial pathname of this file 
  147.                             in ProDOS 8 format.  The string cannot be 
  148.                             longer than 64 characters.
  149.  
  150. If the File Name String is a filename and not a partial pathname, then the 
  151. following optional parameter may be supplied:
  152.  
  153. +039    Native Name String  Pascal string containing the 
  154.                             ASCII value of the native filename.  This 
  155.                             string may not be longer than 48 
  156.                             characters, and will not be present if the 
  157.                             length byte of File Name (+023) is larger 
  158.                             than 15 ($0F).  If this field is 
  159.                             specified, the File Name field must 
  160.                             contain a filename, not a partial 
  161.                             pathname.
  162.  
  163. +088    Reserved   21 Bytes Reserved.  These bytes must be set to zero 
  164.                             for future compatibility.
  165.  
  166. +109    GAux Type  Word     The high word of the file's GS/OS 
  167.                             auxiliary type.
  168. +111    GAccess    Byte     The high byte of the file's GS/OS access 
  169.                             word.
  170. +112    GFile Type Byte     The high byte of the file's GS/OS 
  171.                             file type.
  172. +113    GStorage   Byte     The high byte of the file's GS/OS storage 
  173.                             type.
  174. +114    GFile Size Word     The high word of the GS/OS file's 
  175.                             size in 512-byte blocks.
  176. +116    GEOF       Byte     The high byte of the file's GS/OS EOF 
  177.                             value.
  178. +117    Disk Space Long     The number of 512-byte disk blocks 
  179.                             the files inside the Binary II file will 
  180.                             occupy after they've been removed from the 
  181.                             Binary II file.  (The format of a Binary 
  182.                             II file containing multiple files is 
  183.                             described later in this Note.)  If the 
  184.                             number is zero, the creator of the Binary 
  185.                             II file didn't bother to calculate the 
  186.                             space needed.  This value must be placed 
  187.                             in the file information header for the 
  188.                             first file inside the Binary II file; it 
  189.                             can be set to zero in subsequent headers.  
  190.                             A downloading program can inspect Disk 
  191.                             Space and abort the transfer immediately 
  192.                             if there isn't enough free space on the 
  193.                             disk.
  194. +121    OS Type    Byte     This value indicates the native operating 
  195.                             system of the file:
  196.                             $00    ProDOS or SOS
  197.                             $01    DOS 3.3
  198.                             $02    Reserved
  199.                             $03     DOS 3.2 or DOS 3.1
  200.                             $04    Apple II Pascal
  201.                             $05    Macintosh MFS
  202.                             $06    Macintosh HFS
  203.                             $07    Lisa Filing System
  204.                             $08    Apple CP/M
  205.                             $09    Reserved (returned by the GS/OS 
  206.                                    Character FST)
  207.                             $0A    MS-DOS
  208.                             $0B    High Sierra (CD-ROM)
  209.                             $0C    ISO 9660 (CD-ROM)
  210.                             $0D    AppleShare
  211.                             Note this list is slightly different (in 
  212.                             the first three entries) from the standard 
  213.                             GS/OS file system ID list.  A GS/OS 
  214.                             communication program should not place a 
  215.                             zero in this field unless the file's 
  216.                             native file system truly is ProDOS.  The 
  217.                             file's native file system is returned in 
  218.                             the file_sys_id parameter from the 
  219.                             GetDirEntry call.
  220. +122    Native File Type
  221.                    Word     This has meaning only if OS Type is non-
  222.                             zero.  If so, it is set to the actual file 
  223.                             type code assigned to the file by it's 
  224.                             native operating system.  (Some operating 
  225.                             systems, such as MS-DOS and CP/M, do not 
  226.                             use file type codes, however.)  Contrast 
  227.                             this with the File Type at +004, which is 
  228.                             the closest equivalent ProDOS file type.  
  229.                             The Native File Type is needed to 
  230.                             distinguish files which have the same 
  231.                             ProDOS file type, but which may have 
  232.                             different file types in their native 
  233.                             operating system.  Note that if the file 
  234.                             type code is only one byte long (the usual 
  235.                             case), the high-order byte of Native File 
  236.                             Type is set to zero.
  237. +124    Phantom File Flag
  238.                    Byte     This byte indicates whether a receiver of 
  239.                             the Binary II file should save the file 
  240.                             which follows (flag is zero) or ignore it 
  241.                             (flag is non-zero).  It is anticipated 
  242.                             that some communication programs will use 
  243.                             phantom files to pass non-essential 
  244.                             explanatory notes or encoded information 
  245.                             which would be understood only by a 
  246.                             receiver using the same communication 
  247.                             program.  Such programs must not rely on 
  248.                             receiving a phantom file, however, since 
  249.                             this would mean they couldn't handle 
  250.                             Binary II files created by other 
  251.                             communication programs.  Phantom Files may 
  252.                             also be used to pass extended file 
  253.                             attributes when available.
  254.  
  255.                             The first two bytes in a phantom file must 
  256.                             contain an ID code unique to the 
  257.                             communication program, or a universal 
  258.                             identifier concerning the contents of the 
  259.                             phantom file.  Developers must obtain ID 
  260.                             codes from Gary Little to ensure 
  261.                             uniqueness (see the beginning of this Note 
  262.                             for his address).  Here is a current list 
  263.                             of approved ID codes for phantom files 
  264.                             used by Apple II communication programs:
  265.                             $00 $00    ASCII text terminated with a 
  266.                                        zero byte.
  267.                             $00 $01    Point-to-Point
  268.                             $00 $02    Tele-Master Communications 
  269.                                        System
  270.                             $00 $03    ProTERM
  271.                             $00 $04    Modem MGR
  272.                             $00 $05    CommWorks
  273.                             $00 $06    MouseTalk
  274.                             $01 $00    Option_list data (see later in 
  275.                                        this Note).
  276.                             The ID bytes are the first two bytes of 
  277.                             the phantom file.
  278. +125    Data Flags          Bit 7:    1 = file is compressed
  279.                   Flag Byte Bit 6:    1 = file is encrypted
  280.                             Bits 5-1: Reserved
  281.                             Bit 0:    1 = file is sparse
  282.                             A Binary II downloading program can 
  283.                             examine this byte and warn the user that 
  284.                             the file must be expanded, decrypted or 
  285.                             unpacked.  The person uploading a Binary 
  286.                             II file may use any convenient method for 
  287.                             compressing, encrypting, or packing the 
  288.                             file but is responsible for providing 
  289.                             instructions on how to restore the file to 
  290.                             its original state.
  291. +126    Version    Byte     This release of Binary II has a version 
  292.                             number of $01.
  293. +127    Number of Files to Follow
  294.                    Byte     An appealing feature of Binary II is that 
  295.                             a single Binary II file can hold multiple 
  296.                             disk files, making it easy to keep a group 
  297.                             of related files "glued" together when 
  298.                             they're sent to a host.  This byte 
  299.                             contains the number of files in this 
  300.                             Binary II file that are behind it.  If 
  301.                             this is the first file in a Binary II file 
  302.                             containing three disk files, this byte 
  303.                             would be $02.  The second disk file in the 
  304.                             same Binary II file would have a value of 
  305.                             $01 in this parameter, and the last would 
  306.                             have value $00.  This count tells the 
  307.                             Binary II downloading program how many 
  308.                             files are remaining.  If any phantom files 
  309.                             are included, they must be included in 
  310.                             this count.
  311.  
  312.  
  313. Filenames and Partial Pathnames
  314.  
  315. You can put a standard ProDOS filename or a partial pathname in the file 
  316. information header (but never a complete pathname).  Don't use a partial 
  317. pathname unless you've included, earlier in the Binary II file, file 
  318. information headers for each of the directories referred to in the partial 
  319. pathname.  Such a header must have its "end of file position" bytes set to 
  320. zero, and no data blocks for the subdirectory file must follow it.
  321.  
  322. For example, if you want to send a file whose partial pathname is 
  323. HELP/GS/READ.ME, first send a file information header defining the HELP/ 
  324. subdirectory, then one defining the HELP/GS/ subdirectory.  If you don't, 
  325. someone downloading the Binary II file won't be able to convert it because the 
  326. necessary subdirectories will not exist.
  327.  
  328. Note:  GS/OS communication programs must use the slash (/) as the 
  329.        pathname's separator in any partial pathname it puts in the 
  330.        header.  Since GS/OS's standard separator is the colon (:), a 
  331.        conversion may be necessary.
  332.  
  333.  
  334. Filename Convention
  335.  
  336. Whenever a file is sent to a host, the host asks the sender to provide a name 
  337. for it.  If it's a file in Binary II form, the name provided should end in 
  338. .BNY so its special form will be apparent to anyone viewing a list of 
  339. filenames.  If the file is compacted (using the public-domain Squeeze 
  340. algorithm) before being converted to Binary II form, use a .BQY suffix 
  341. instead.  If the file is a NuFX archive, use the suffix .BXY.
  342.  
  343.  
  344. Identifying Binary II Files
  345.  
  346. You can determine, while transferring, if a file is in Binary II form by 
  347. examining the ID bytes at offsets +000, +001, +002 and +018 from the beginning 
  348. of the file.  They must be $0A, $47, $4C and $02, respectively.
  349.  
  350. Once Binary II files are identified, you can use the data in the file 
  351. information header to create and open a ProDOS file with the correct name and 
  352. attributes, transfer the file data in the Binary II file to the ProDOS file, 
  353. set the ProDOS file size, then close the ProDOS file.  You would repeat this 
  354. for each file contained inside the Binary II file.
  355.  
  356. Note:  The number of 128-byte blocks following the file information 
  357.        header must be derived from the EOF attribute for the file.  
  358.        Calculate the number by dividing the EOF by 128 and adding one to 
  359.        the result if EOF is not 0 or an exact multiple of 128.  However, 
  360.        if the file information header defines a subdirectory (the file 
  361.        type is $0F), simple create the subdirectory file.  Do not open it 
  362.        and do not try to set its size.
  363.  
  364. Ideally, all this conversion work will be done automatically by a 
  365. communication program during file transfer.  If not, a separate conversion 
  366. program (such as the previously mentioned Binary Library Utility, or BLU) must 
  367. be used to do this for you.
  368.  
  369.  
  370. Option_List Phantom Files
  371.  
  372. GS/OS will return, when asked, an option_list for files on many file calls.  
  373. The option_list consists of a Word buffer length (which must be at least $2E), 
  374. followed by a Word number of bytes GS/OS put in the buffer, a Word GS/OS file 
  375. system identification, and the given number of bytes of FST-specific 
  376. information (minus two; the count GS/OS returns includes the file system 
  377. identifier).
  378.  
  379. Option_list values are FST specific and contain values important to the native 
  380. file system but not important to GS/OS.  For AppleShare, the option_list 
  381. contains Finder Information, parent directory identification, and access 
  382. privileges.  This information should be transferred with files.
  383.  
  384. Binary II uses a phantom file with identifier $01 $00 to indicate an 
  385. option_list.  When this phantom file is seen, the contents should be used as 
  386. the option_list for the file that immediately follows this file in the 
  387. Binary II file.  The other attributes of the phantom file must be set to the 
  388. same values as those for the file immediately following (the file for which 
  389. the phantom file contains the option_list).  The EOF for the phantom file must 
  390. be the size of the option_list + 2, and the file size must be adjusted 
  391. accordingly to account for the phantom file ID bytes.
  392.  
  393. When receiving a Binary II file, the contents of this phantom file should be 
  394. used as option_list input on a GS/OS SetFileInfo call.
  395.  
  396. If the GS/OS option_list returns a total of two bytes (just the file_sys_ID), 
  397. there is no FST-specific information, and the option_list phantom file may 
  398. safely be omitted.
  399.  
  400. The format of the option_list phantom file is as follows:
  401.  
  402. +000    Phantom ID 2 Bytes  The identifying bytes $01 $00.
  403. +002    List Size  Word     The length of the bytes in the 
  404.                             option_list, starting with the file system 
  405.                             ID (the next word).
  406. +004    FileSysID  Word     A GS/OS (not Binary II) file_sys_ID for 
  407.                             the volume on which the file was stored.
  408. +006    List Bytes Bytes    The bytes of the option list.  
  409.                             There should be (List Size) of them, 
  410.                             counting the previous word (FileSysID).
  411.  
  412.  
  413. Extended File Considerations
  414.  
  415. Extended files contain two logical segments:  a data fork and a resource fork.  
  416. These files can be created and manipulated by GS/OS, but not by ProDOS 8 or 
  417. any other Apple II operating system.
  418.  
  419. When a GS/OS-based communication program sends an extended file, it must send 
  420. it in the AppleSingle file format, preceded by a Binary II file information 
  421. header.  (Such a program could easily convert an extended file to AppleSingle 
  422. format on the fly.)  The Binary II header must contain the attributes of the 
  423. AppleSingle file (including a file type of $E0 and an auxiliary type of $0001) 
  424. and the "storage type code" field must be $01.  (The EOF positions for the 
  425. data fork and resource fork of the extended file appear in an entry in the 
  426. AppleSingle file header, not in the Binary II header.)
  427.  
  428. The AppleSingle format is described in Apple II File Type Note for File Type 
  429. $E0, Auxiliary Type $0001.
  430.  
  431. A GS/OS-based communication program that receives an AppleSingle file can 
  432. easily convert it on the fly to the extended file it defines.  ProDOS 8-based 
  433. communication programs can only save the AppleSingle file to disk because it's 
  434. not possible (nor is it encouraged to attempt) to create extended files with 
  435. ProDOS 8 (without using block-level calls); a GS/OS based utility program is 
  436. needed to convert the AppleSingle file to its extended form.
  437.  
  438.  
  439. DOS 3.3 Considerations
  440.  
  441. With a little extra effort, you can also convert DOS 3.3 files to Binary II 
  442. form.  This involves translating the DOS 3.3 file attributes to the 
  443. corresponding ProDOS attributes so that you can build a proper file 
  444. information header.
  445.  
  446.   o  Set the name to one that adheres to the stricter ProDOS naming 
  447.      rules and put its length at +023 and the name itself at +024 to 
  448.      +038.  Note that the name must be a simple filename and not a 
  449.      pathname.  The actual DOS 3.3 filename must be placed at +039 
  450.      (length) and +040 to +087 (name).  (DOS 3.3 actually restricts 
  451.      filenames to 30 characters.)
  452.  
  453.   o  Set the ProDOS file type, auxiliary type and access to values 
  454.      which correspond to the DOS 3.3 file type:
  455.  
  456.         DOS 3.3      ProDOS       ProDOS            ProDOS
  457.         File Type    File Type    Auxiliary Type    Access
  458.         __________________________________________________
  459.         $00 (T)       $04            $0000           $E3
  460.         $80 (*T)      $04            $0000           $21
  461.         $01 (I)       $FA            $0C00           $E3
  462.         $81 (*I)      $FA            $0C00           $21
  463.         $02 (A)       $FC            *               $E3
  464.         $82 (*A)      $FC            *               $21
  465.         $04 (B)       $06            **              $E3
  466.         $84 (*B)      $06            **              $21
  467.         $08 (S)       $06            $0000           $E3
  468.         $88 (*S)      $06            $0000           $21
  469.         $10 (R)       $FE            $0000           $E3
  470.         $90 (*R)      $FE            $0000           $21
  471.         $20 (A)       $06            $0000           $E3
  472.         $A0 (*A)      $06            $0000           $E3
  473.         $40 (B)       $06            $0000           $E3
  474.         $C0 (*B)      $06            $0000           $21
  475.         __________________________________________________
  476.  
  477.         *  Set the auxiliary type for an A file to the
  478.            memory address from which the program was saved.
  479.            This is usually $0801.
  480.         ** Set the auxiliary type for a B file to the
  481.            value stored in the first two bytes of the the
  482.            file (this is the default load address).
  483.  
  484.   o  Set the storage type code to $01.
  485.   o  Set the size of file in blocks, date of creation, date of 
  486.      modification, time of creation and time of modification all to 
  487.      $0000.
  488.   o  Set the end-of-file position to the length of the DOS 3.3 file, in 
  489.      bytes.  For a B file (code $04 or $84), this number is stored in 
  490.      the third and fourth bytes of the file.  For an I file (code $01 
  491.      or $81) or an A file (code $02 or $82), this number is stored in 
  492.      the first and second bytes of the file.
  493.   o  Set the operating system type to $01.
  494.   o  Set the native file type code to the value of the DOS 3.3 file 
  495.      type code.
  496.  
  497. Attribute bytes inside a DOS 3.3 file (if any) must not be included in the 
  498. data portion of the Binary II file.  This includes the first four bytes of a B 
  499. (Binary) file, and the first two bytes of an A (AppleSoft) or I (Integer 
  500. BASIC) file.
  501.  
  502.  
  503. Further Reference
  504. _____________________________________________________________________________
  505.     o    GS/OS Reference
  506.     o    ProDOS 8 Technical Reference Manual
  507.     o    Apple II File Type Note, File Type $E0, Auxiliary Type $0001
  508.     o    Apple II File Type Note, File Type $E0, Auxiliary Type $8002
  509.     o    Apple II Miscellaneous Technical Note #14, Guidelines for 
  510.          Telecommunication Programs